home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / lang / ada / adaed-1.11 / adaed-1 / Adaed-1.11.0a / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-02-07  |  8.9 KB  |  359 lines

  1. /*
  2.  * Copyright (C) 1985-1992  New York University
  3.  * 
  4.  * This file is part of the Ada/Ed-C system.  See the Ada/Ed README file for
  5.  * warranty (none) and distribution info and also the GNU General Public
  6.  * License for more details.
  7.  
  8.  */
  9.  
  10. #include "hdr.h"
  11. #include "vars.h"
  12. #include "libhdr.h"
  13. #include "ifile.h"
  14. #include "libprots.h"
  15. #include "libfprots.h"
  16. #include "librprots.h"
  17. #include "libwprots.h"
  18. #include "setprots.h"
  19. #include "dbxprots.h"
  20. #include "arithprots.h"
  21. #include "miscprots.h"
  22. #include "smiscprots.h"
  23. #include "chapprots.h"
  24. #include "astreadprots.h"
  25. #include "dclmapprots.h"
  26. #include "sspansprots.h"
  27.  
  28. IFILE *TREFILE;
  29. IFILE *AISFILE, *STUBFILE;
  30. IFILE *LIBFILE;
  31. FILE *MALFILE;
  32. int list_unit_0=0; /* on to list structure of unit 0 */
  33.  
  34. static int malloc_usage_list=0;
  35. static unsigned malloc_bytes;
  36.  
  37. static void exitf(int);
  38.  
  39. #ifdef DEBUG
  40. extern int zpadr_opt;
  41. #endif
  42.  
  43. int main (int argc, char **argv)                                    /*;main*/
  44. {
  45.     /* Driver routine for ada sem */
  46.  
  47.     Node nod;
  48.     int        c, i, n;
  49.     int        errflg = 0, nobuffer = 0;
  50.     int        mflag = 0;
  51.     int        compiling_predef = 0;
  52.     int        dir_option=FALSE;
  53.     int        iot_prs_r=0; /* prs tree input trace */
  54.     int        iot_level=2; /* default trace level */
  55.     extern int    optind;
  56.     extern char *optarg;
  57.     IFILE    *astfile;
  58.     char    *fname, *tfname;
  59.     char    *lib_name, *t_name;
  60.     int        r_trace=TRUE, w_trace =TRUE;
  61.  
  62.     AISFILE = (IFILE *)0;
  63.     STUBFILE= (IFILE *)0;
  64.  
  65.     while ((c = getopt (argc, argv, "f:l:ns:")) != EOF)
  66.         /*   user:
  67.          *      l    using library
  68.          *      n    new library
  69.          *   debugging: 
  70.          *    f    file i/o trace, followed by list of options
  71.          *        a    trace ais files
  72.          *        d    do not include descriptors in trace
  73.          *        n    do not include file numbers in trace
  74.          *        p    trace ast file
  75.          *        r    subsequent traces for reading only
  76.          *        t    trace tre files
  77.          *        w    subsequent traces for writing only
  78.          *        (traces initially for both r and w, use of r or w
  79.          *        limits further files traces to just that mode)
  80.          *        1    set trace level to 1
  81.          *        2    set trace level to 2
  82.          *    s    debugging, followed by list of options:
  83.          *        0    show structure of unit 0
  84.          *        M    malloc trace (including init_sem)
  85.          *        b    do not buffer standard output
  86.          *        d    debug trace
  87.          *        e    flag signalling errors in the parsing phase
  88.          *        m    malloc trace (after init_sem)
  89.          *        p    compiling predef units
  90.          *        z    call trapini to initialize traps
  91.          */
  92.  
  93.         switch (c) {
  94.         case 'l': /* using existing library */
  95.             lib_option = TRUE;
  96.             lib_name = emalloc((unsigned) (strlen(optarg) + 1));
  97.             strcpy(lib_name, optarg);
  98.             break;
  99.         case 'n': /* indicates new library */
  100.             new_library = TRUE;
  101.             lib_option = TRUE;
  102.             break;
  103. #ifdef DEBUG
  104.         case 'f':    /* process ifile trace options */
  105.             n = strlen(optarg);
  106.             for (i=0; i<n; i++) {
  107.                 switch (optarg[i]) {
  108.  
  109.                 case 'o': /* suppress offset info */
  110.                     iot_off_info(0);
  111.                     break;
  112.                 case 'a':
  113.                     if (w_trace) iot_ais_w = iot_level;
  114.                     if (r_trace) iot_ais_r = iot_level;
  115.                     break;
  116.                 case 't':
  117.                     if (w_trace) iot_tre_w = iot_level;
  118.                     if (r_trace) iot_tre_r = iot_level;
  119.                     break;
  120.                 case 'l':
  121.                     if (w_trace) iot_lib_w = iot_level;
  122.                     if (r_trace) iot_lib_r = iot_level;
  123.                     break;
  124.                 case 'n': 
  125.                     iot_set_opt_number(0);
  126.                     break;
  127.                 case 'p': 
  128.                     iot_prs_r = iot_level;
  129.                     break;
  130.                 case 'd': 
  131.                     iot_set_opt_desc(0); 
  132.                     break;
  133.                 case 'r': 
  134.                     w_trace= FALSE; 
  135.                     r_trace= TRUE; 
  136.                     break;
  137.                 case 'w': 
  138.                     r_trace = FALSE; 
  139.                     w_trace = TRUE; 
  140.                     break;
  141.                 case '1': 
  142.                     iot_level = 1; 
  143.                     break;
  144.                 case '2': 
  145.                     iot_level = 2; 
  146.                     break;
  147.                 }
  148.             }
  149.             break;
  150. #endif
  151.         case 's':
  152.             n = strlen(optarg);
  153.             for (i=0; i <= n; i++) {
  154.                 switch(optarg[i]) {
  155.  
  156. #ifdef DEBUG
  157.                 case 'a':
  158.                     zpadr_opt = 0;
  159.                     break;
  160. #endif
  161.                 case 'e':
  162.                     errors = TRUE;
  163.                     break;
  164.                 case 'p': /* compiling predef units */
  165.                     compiling_predef++;
  166.                     break;
  167. #ifdef DEBUG
  168.                 case '0':  /* dump unit 0 */
  169.                     list_unit_0++;
  170.                     break;
  171.                 case 'b': /* do not buffer output */
  172.                     nobuffer++;
  173.                     break;
  174.                 case 'd': /* force debugging output */
  175.                     cdebug2 = 4;
  176.                     break;
  177.                 case 'm': /* turn on malloc trace */
  178.                     mflag++;
  179.                     break;
  180.                 case 't': /* save_tree trace */
  181.                     zpadr_opt=0;
  182.                     save_trace_init();
  183.                     break;
  184.                 case 'u': /* malloc usage */
  185.                     malloc_usage_list++;
  186.                     break;
  187.                 case 'z':
  188.                     trapini();
  189.                     break;
  190. #endif
  191.                 }
  192.             }
  193.             break;
  194.         case '?':
  195.             errflg++;
  196.         }
  197.     fname = (char *)0;
  198.     if (optind < argc)
  199.         fname = argv[optind];
  200.     if (fname == (char *)0) errflg++;
  201.     if (errflg) {
  202.         printf ("Usage: adasem -n -l library -s [AMRabdemprtwz] file\n");
  203.         exitp(RC_ABORT);
  204.     }
  205. #ifdef DEBUG
  206.     if (mflag) {
  207.         trace_malloc();
  208.         /* can't use strjoin to setup efopen arg as want trace ! */
  209.         /*MALFILE = efopen(strjoin(FILENAME, ".mas"), "w", "t"); */
  210.         tfname = malloc((unsigned) (strlen(fname) + 4 + 1));
  211.         MALFILE = efopen(strcat(strcpy(tfname, fname), ".mas"), "w", "t");
  212.         free(tfname);
  213.     }
  214. #endif
  215.     tup_init(); /* initialize tuple package */
  216.     FILENAME = strjoin(fname, "");
  217.     PREDEFNAME = predef_env();
  218.     if (nobuffer) {
  219.         setbuf (stdout, (char *)0); /* do not buffer output (for debug) */
  220.     }
  221.     dstrings_init(2048, 512); /* initialize dstrings package */
  222.  
  223.     rat_init(); /* initialize arithmetic and rational package*/
  224.     init_sem();
  225.  
  226.     aisunits_read = tup_new(0);
  227.     init_symbols = tup_exp(init_symbols, (unsigned)  seq_symbol_n);
  228.     for (i=1; i<= seq_symbol_n; i++)
  229.         init_symbols[i] = seq_symbol[i];
  230.  
  231.     t_name = libset(lib_name);
  232.     MSGFILE  = efopenl(FILENAME, "msg", "a", "t");
  233.     if (!compiling_predef) init_predef();
  234.     /* When the separate compilation facility is being used all references to
  235.      * AIS files will be made via the directory in LIBFILE. AISFILENAME is set
  236.      * to a number if the library is used, otherwise it is the FILENAME.  
  237.      */
  238.     if (lib_option) {
  239.         if (compiling_predef)
  240.             AISFILENAME = "0";
  241.         else if (new_library) 
  242.             AISFILENAME = "1";
  243.         else {
  244.             /* here to get AIS name from lib. Note the library is left open*/
  245.             AISFILENAME = lib_aisname();
  246.             read_lib();
  247.         }
  248.     }
  249.     else {
  250.         AISFILENAME = FILENAME;
  251.     }
  252.     /* open the appropriate files using the suffix  .aic for ais files and
  253.      * .trc for tree file. 
  254.      */
  255.     astfile  = ifopen(FILENAME, "ast", "r", "p", iot_prs_r, 0);
  256.     AISFILE  = ifopen(AISFILENAME, "aic", "w", "a", iot_ais_w, 0);
  257.     TREFILE  = ifopen(AISFILENAME, "trc", "w", "t", iot_tre_w, 0);
  258.     /* delete any existing stubfile for current AISFILENAME */
  259.     ifdelete(strjoin(AISFILENAME, ".st1"));
  260.     /* unbuffer output for debugging purposes */
  261.     setbuf(MSGFILE, (char *) 0);
  262.     /* ignore first unit (due to pragmas) */
  263.     nod =astreadu(astfile);
  264.     if (N_KIND(nod) == as_astend) exitf(errors ? RC_ERRORS : RC_SUCCESS);
  265.     for (;;) {
  266.         unit_number_now = unit_numbers + 1;
  267.         seq_node_n = 0; /* reset node count */
  268.         seq_symbol_n = 0; /* reset symbol count */
  269.         nod =astreadu(astfile);
  270.         if (N_KIND(nod) == as_astend) break;
  271.         adasem(nod);
  272.     }
  273.  
  274.     exitf(errors ? RC_ERRORS : RC_SUCCESS);
  275. }
  276.     
  277. static void exitf(int status)                                        /*;exitf*/
  278. {
  279.     /* exit after closing any unclosed files */
  280.  
  281.     ifoclose(AISFILE);
  282.     ifoclose(STUBFILE);
  283.     ifoclose(TREFILE);
  284.     if (malloc_usage_list) {
  285.  
  286.  
  287. #ifdef MSTAT
  288.         mstats("malloc use");
  289. #endif
  290.         /*printf("malloc got %u bytes\n", malloc_bytes); */
  291.     }
  292.     exitp(status);
  293. }
  294.  
  295. /* The following procedures  errmsg() and warning() - should properly 
  296.  * be in errmsg.c, but are placed here to avoid a problem with 
  297.  * overlaying on PC, so that errmsg can be overlaid with eval. 
  298.  * There are calls to errmsg() and warning() in eval that cause loop
  299.  * on PC if these procedures in errmsg.
  300.  */
  301.  
  302. void errmsg(char *msg, char *lrm_sec, Node node)                /*;errmsg*/
  303. {
  304.     /* Semantic errors */
  305.  
  306.     int begline, begcol, endline, endcol;
  307.     Span lspan, rspan;
  308.  
  309.     if (cdebug2 > 3) TO_ERRFILE("AT PROC : errmsg(msg, lrm_sec, node); ");
  310.  
  311.     if (node == OPT_NODE) node = current_node;
  312.     if (node != (Node)0) {
  313.         lspan = get_left_span(node);
  314.         rspan = get_right_span(node);
  315.         begline = lspan->line;
  316.         begcol    = lspan->col;
  317.         endline = rspan->line;
  318.         endcol    = rspan->col;
  319.     }
  320.     else 
  321.         /* this is in case rcv null node - put message at beginning of file*/
  322.         /* only temp-eventually, all calls to errmsg should have valid node */
  323.         begline = begcol = endline = endcol = 1;
  324.  
  325.     fprintf(MSGFILE, "%d %d %d %d %d\t%s", ERR_SEMANTIC, begline, begcol,
  326.       endline, endcol, msg);
  327.     if (!streq(lrm_sec, "none"))
  328.         fprintf(MSGFILE, " (RM %s)", lrm_sec);
  329.     fprintf(MSGFILE, "\n");
  330.     errors = TRUE;
  331. }
  332.  
  333. void warning(char *msg, Node node)                                /*;warning*/
  334. {
  335.     int begline, begcol, endline, endcol;
  336.     Span lspan, rspan;
  337.  
  338.     if (cdebug2 > 3) TO_ERRFILE("AT PROC : warning(msg);");
  339.  
  340.     if (node == OPT_NODE) node = current_node;
  341.     if (node != (Node)0) {
  342.         lspan = get_left_span(node);
  343.         rspan = get_right_span(node);
  344.         begline = lspan->line;
  345.         begcol    = lspan->col;
  346.         endline = rspan->line;
  347.         endcol    = rspan->col;
  348.     }
  349.     else 
  350.         /* this is in case rcv null node - put message at beginning of file*/
  351.         /* only temp-eventually, all calls to errmsg should have valid node */
  352.         begline = begcol = endline = endcol = 1;
  353.  
  354.     fprintf(MSGFILE, "%d %d %d %d %d\t%s", ERR_WARNING, begline, begcol,
  355.       endline, endcol, msg);
  356.     fprintf(MSGFILE, "\n");
  357. }
  358.  
  359.